package fanshe.second.demo03;

import java.lang.reflect.Field;

/**
 * @author Mr.ma
 * @since 2022/10/27 20:14
 **/
public class Test03 {
    public static void main(String[] args) throws Exception {
        doSome();
        doOther();
    }
    public static void doSome(){
        Class<B> bClass = B.class;
        Field[] fields = bClass.getFields();
        for (Field field : fields) {
            System.out.println("field = " + field.getName());
        }
        Field[] declaredFields = bClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            System.out.println("declaredField = " + declaredField.getName());
        }
    }
    public static void doOther() throws Exception {
        B b = new B();
        Class<? extends B> aClass = b.getClass();
        Field b1 = aClass.getDeclaredField("b");
        b1.setAccessible(true);
        b1.set(b,"小");
        System.out.println(b1.get(b));
    }
}

class B extends A{
    private String b;
    String bb;
    protected String bbb;
    public String bbbb;
}
class A {
    private String a;
    public String aa;
    String aaa;
    protected String aaaa;
}